< previous page page_377 next page >

Page 377
12180-0377a.gif
Figure 17.1.
The File Operations Subsystem's pattern of classes.
Random File Management
Using Visual Basic's random access file management is good for record-oriented files. Like a spreadsheet or database table, a random access file has rows and columns. A row, which is a record, that has only one column is good for populating list or combo boxes. The sole column can handle data of types such as an integer or fixed-length string. If the file contains a row with more than one column, you can map each row to a user-defined type (UDT). For instance, if you persisted the transactions of a bank teller to a random access file, you can map each row of the file to a UDT named BankTellerTrans, which can look like
Type BankTellerTrans
     UserID        As String * 12
     TransID       As String * 12
     DateTiemStamp    As Date
     AccountNum     As String * 15
End Type
Declaring the BankTellerTrans UDT, or any other variable, should occur before accessing the file. If you're not careful in making sure that a UDT maps properly to each two in the random access file, including data types and column lengths, be prepared for lots of debugging effort. In the case of column lengths, if the column is expecting a string of 12 characters (As String * 12), and you only pass in eight, Visual Basic inserts four additional spaces (called padding, with each space known as a trailing space). If your value is longer than the 12-character limit, the value is truncated. Thus, it is wise to be careful in planning file formats.

 
< previous page page_377 next page >

If you like this book, buy it!